﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Backend.JYD.Model;
using Backend.JYD.Model.Auth;
using Backend.JYD.Business;

namespace Backend.JYD.RunTime
{
    public class AbController : Controller
    {
        protected RoleManager roleManager = new RoleManager();
        protected AuthManager authManager = new AuthManager();

        /// <summary>
        /// 登陆员工信息
        /// </summary>
        protected EmpInfo LoginEmpInfo { get; private set; }

        /// <summary>
        /// 登陆员工角色列表
        /// </summary>
        protected List<RoleInfo> LoginRoleInfos { get; private set; }
        /// <summary>
        /// 登陆员工主角色
        /// </summary>
        protected RoleInfo MainRoleInfo { get; private set; }

        // 权限列表
        protected List<AuthorityInfo> LoginAuthorityInfoes { get; private set; }


        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var empInfo = SessionMgr.GetEmpInfoFromSession(this.HttpContext);
            if (empInfo != null)
            {
                this.LoginEmpInfo = empInfo;
                this.ViewBag.LoginEmpInfo = this.LoginEmpInfo;
            }

            if (this.LoginEmpInfo != null)
            {
                this.LoginRoleInfos = roleManager.GetRoleInfoByEmpId(this.LoginEmpInfo.EmpId);
                this.MainRoleInfo = roleManager.GetMainRoleInfoByEmpId(this.LoginEmpInfo.EmpId);
                this.LoginAuthorityInfoes = authManager.GetEmpAuthorityInfoesByEmpId(this.LoginEmpInfo.EmpId);

                this.ViewBag.LoginEmpInfo = this.LoginEmpInfo;
                this.ViewBag.MainRoleInfo = this.MainRoleInfo;
                this.ViewBag.LoginRoleInfos = this.LoginRoleInfos;
                this.ViewBag.LoginAuthorityInfoes = this.LoginAuthorityInfoes;
            }
        }
    }
}
